package com.changpay.zywy.adapter

import android.content.Context
import android.widget.GridView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.changpay.zywy.R
import com.changpay.zywy.bean.MyPartent
import com.changpay.zywy.utils.ImageLoader
import com.changpay.zywy.utils.StringUtil

/**
 * Created by chenxz on 2018/4/22.
 */
class MyPartentAdapter(private val context: Context?, datas: MutableList<MyPartent.ListBean>) :
    BaseQuickAdapter<MyPartent.ListBean, BaseViewHolder>(R.layout.item_partner, datas) {
    override fun convert(helper: BaseViewHolder?, item: MyPartent.ListBean?) {
        item ?: return
        helper ?: return

        ImageLoader.loadAvatar(item.member_avatar, helper.getView(R.id.iv_head))
        helper.setText(R.id.tv_name, item.truename)
            .setText(R.id.tv_phone, item.member_mobile)
            .setText(R.id.tv_time, item.created_date)
        formatDouble(helper.getView(R.id.tv_money), item.total_price.toDouble())
        formatDouble(helper.getView(R.id.tv_total_money), item.trading_amount.toDouble())
        helper.getView<GridView>(R.id.grid_view).adapter = MarchieActionAdapter(context,item.activation_info,item.member_id.toString(),item.truename)
    }

    private fun formatDouble(view: TextView, value: Double) {

        if (value >= 10000) {
            val n = value / 10000
            view.text = "¥ " + StringUtil.formatDouble(n) + "万"
        } else {
            view.text = "¥ " + StringUtil.formatDouble(value)
        }
    }



}
